package com.sany.assess.config;

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @Author fenglf
 * @Date 7/12/20
 * @Version 1.0
 * @Description : MybatisPlusConfig 实体类
 */
@Configuration
@EnableTransactionManagement
public class MybatisPlusConfig {

    private Log logger = LogFactory.getLog(MybatisPlusConfig.class);

    /**
     * 性能分析拦截器，不建议生产使用 用来观察 SQL 执行情况及执行时长, 默认dev,staging 环境开启
     *
     * @return com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
     * @author fxbin
     */
    @Bean
    @Profile({"dev", "staging"})
    public PerformanceInterceptor performanceInterceptor() {
        //启用性能分析插件, SQL是否格式化 默认false,此处开启
        return new PerformanceInterceptor().setFormat(true);
    }

    /**
     * mybatis-plus分页插件
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        PaginationInterceptor page = new PaginationInterceptor();
        page.setDialectType("mysql");
        //        page.setLimit(-1);
        return page;
    }
}
